import Storage from 'web-storage-cache'

const localStorage = new Storage()

// 设置localStorage
export function setLocalStorage(key, value) {
  return localStorage.set(key, value)
}

// 获取localStorage
export function getLocalStorage(key) {
  return localStorage.get(key)
}

// 删除localStorage
export function removeLocalStorage(key) {
  return localStorage.delete(key)
}

// 清除所有localStorage
export function clearLocalStorage() {
  return localStorage.clear()
}

export function setBookObject(fileName, key, value) {
  let book = getLocalStorage(`${fileName}-info`)
  if (!book) {
    book = {}
  }
  book[key] = value
  setLocalStorage(`${fileName}-info`, book)
}

export function getBookObject(fileName, key) {
  let book = getLocalStorage(`${fileName}-info`)
  return book ? book[key] : null
}

export function setFontSize(fileName, value) {
  setBookObject(fileName, 'fontSize', value)
}

export function getFontSize(fileName) {
  return getBookObject(fileName, 'fontSize')
}

export function setFontFamily(fileName, value) {
  setBookObject(fileName, 'fontFamily', value)
}

export function getFontFamily(fileName) {
  return getBookObject(fileName, 'fontFamily')
}

export function setTheme(fileName, value) {
  setBookObject(fileName, 'theme', value)
}

export function getTheme(fileName) {
  return getBookObject(fileName, 'theme')
}
